package nl.science.uva.pico.operand;

/** 
 * Operands are the variables in a stack program; they're either Integers or Strings 
 * 
 * @author Ivo van Dongen, Karel Pieterson
 * @version 1.0
 */
public class Operand {

	private Object value;

	public Operand(Object value) {
		if(!(value instanceof String || value instanceof Integer)) {
			throw new IllegalArgumentException();
		}
		
		this.value = value;
	}
	
	/** 
	 * Return value as a String
     *  
     *  @return String
     */		
	public String getStringValue() {
		if(!isStringConstant()) {
			throw new IllegalStateException("geen string");
		}
		return (String)value;
	}

	
	/** 
	 * Return value as an Integer
     *  
     *  @return Integer
     */		
	public Integer getIntegerValue() {
		if(!isIntegerConstant()) {
			throw new IllegalStateException("geen int");
		}
		return (Integer)value;
	}
		
	/** 
	 * Determine whether a value is a String 
     *  
     *  @return boolean
     */		
	public boolean isStringConstant() {
		if(value instanceof String) {
			return true;
		} else {
			return false;
		}
	}
	
	/** 
	 * Determine whether a value is an Integer 
     *  
     *  @return boolean
     */		
	public boolean isIntegerConstant() {
		if(value instanceof Integer) {
			return true;
		} else {
			return false;
		}
	}
	
	/** 
	 * Return value as String 
     *  
     *  @return String
     */		
	@Override
	public String toString() {
		return value.toString();
	}
}
